
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 2016/10/8 0:58:26
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace yncTech.BusinessObjects
{
	/// <summary>
	/// Encapsulates the 'Fin_Receipt_His' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(FinReceiptHis))]	
	[XmlType("FinReceiptHis")]
	public partial class FinReceiptHis : esFinReceiptHis
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new FinReceiptHis();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Decimal hisId)
		{
			var obj = new FinReceiptHis();
			obj.HisId = hisId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Decimal hisId, esSqlAccessType sqlAccessType)
		{
			var obj = new FinReceiptHis();
			obj.HisId = hisId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("FinReceiptHisCollection")]
	public partial class FinReceiptHisCollection : esFinReceiptHisCollection, IEnumerable<FinReceiptHis>
	{
		public FinReceiptHis FindByPrimaryKey(System.Decimal hisId)
		{
			return this.SingleOrDefault(e => e.HisId == hisId);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(FinReceiptHis))]
		public class FinReceiptHisCollectionWCFPacket : esCollectionWCFPacket<FinReceiptHisCollection>
		{
			public static implicit operator FinReceiptHisCollection(FinReceiptHisCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator FinReceiptHisCollectionWCFPacket(FinReceiptHisCollection collection)
			{
				return new FinReceiptHisCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class FinReceiptHisQuery : esFinReceiptHisQuery
	{
        public FinReceiptHisQuery() : this("FinReceiptHisQuery")
		{
		}
        
        public FinReceiptHisQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "FinReceiptHisQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(FinReceiptHisQuery query)
		{
			return FinReceiptHisQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator FinReceiptHisQuery(string query)
		{
			return (FinReceiptHisQuery)FinReceiptHisQuery.SerializeHelper.FromXml(query, typeof(FinReceiptHisQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esFinReceiptHis : esEntity
	{
		public esFinReceiptHis()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Decimal hisId)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(hisId);
			else
				return LoadByPrimaryKeyStoredProcedure(hisId);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Decimal hisId)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(hisId);
			else
				return LoadByPrimaryKeyStoredProcedure(hisId);
		}

		private bool LoadByPrimaryKeyDynamic(System.Decimal hisId)
		{
			FinReceiptHisQuery query = new FinReceiptHisQuery();
			query.Where(query.HisId == hisId);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Decimal hisId)
		{
			esParameters parms = new esParameters();
			parms.Add("HisId", hisId);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to Fin_Receipt_His.HisId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? HisId
		{
			get
			{
				return base.GetSystemDecimal(FinReceiptHisMetadata.ColumnNames.HisId);
			}
			
			set
			{
				if(base.SetSystemDecimal(FinReceiptHisMetadata.ColumnNames.HisId, value))
				{
					OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.HisId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Fin_Receipt_His.ReceiptId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? ReceiptId
		{
			get
			{
				return base.GetSystemDecimal(FinReceiptHisMetadata.ColumnNames.ReceiptId);
			}
			
			set
			{
				if(base.SetSystemDecimal(FinReceiptHisMetadata.ColumnNames.ReceiptId, value))
				{
					OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.ReceiptId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Fin_Receipt_His.Content
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Content
		{
			get
			{
				return base.GetSystemString(FinReceiptHisMetadata.ColumnNames.Content);
			}
			
			set
			{
				if(base.SetSystemString(FinReceiptHisMetadata.ColumnNames.Content, value))
				{
					OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.Content);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Fin_Receipt_His.CreateUser
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String CreateUser
		{
			get
			{
				return base.GetSystemString(FinReceiptHisMetadata.ColumnNames.CreateUser);
			}
			
			set
			{
				if(base.SetSystemString(FinReceiptHisMetadata.ColumnNames.CreateUser, value))
				{
					OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.CreateUser);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Fin_Receipt_His.CreateDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreateDate
		{
			get
			{
				return base.GetSystemDateTime(FinReceiptHisMetadata.ColumnNames.CreateDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(FinReceiptHisMetadata.ColumnNames.CreateDate, value))
				{
					OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.CreateDate);
				}
			}
		}		
		
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "HisId": this.str().HisId = (string)value; break;							
						case "ReceiptId": this.str().ReceiptId = (string)value; break;							
						case "Content": this.str().Content = (string)value; break;							
						case "CreateUser": this.str().CreateUser = (string)value; break;							
						case "CreateDate": this.str().CreateDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "HisId":
						
							if (value == null || value is System.Decimal)
								this.HisId = (System.Decimal?)value;
								OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.HisId);
							break;
						
						case "ReceiptId":
						
							if (value == null || value is System.Decimal)
								this.ReceiptId = (System.Decimal?)value;
								OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.ReceiptId);
							break;
						
						case "CreateDate":
						
							if (value == null || value is System.DateTime)
								this.CreateDate = (System.DateTime?)value;
								OnPropertyChanged(FinReceiptHisMetadata.PropertyNames.CreateDate);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esFinReceiptHis entity)
			{
				this.entity = entity;
			}
			
	
			public System.String HisId
			{
				get
				{
					System.Decimal? data = entity.HisId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.HisId = null;
					else entity.HisId = Convert.ToDecimal(value);
				}
			}
				
			public System.String ReceiptId
			{
				get
				{
					System.Decimal? data = entity.ReceiptId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ReceiptId = null;
					else entity.ReceiptId = Convert.ToDecimal(value);
				}
			}
				
			public System.String Content
			{
				get
				{
					System.String data = entity.Content;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Content = null;
					else entity.Content = Convert.ToString(value);
				}
			}
				
			public System.String CreateUser
			{
				get
				{
					System.String data = entity.CreateUser;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreateUser = null;
					else entity.CreateUser = Convert.ToString(value);
				}
			}
				
			public System.String CreateDate
			{
				get
				{
					System.DateTime? data = entity.CreateDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreateDate = null;
					else entity.CreateDate = Convert.ToDateTime(value);
				}
			}
			

			private esFinReceiptHis entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return FinReceiptHisMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public FinReceiptHisQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new FinReceiptHisQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(FinReceiptHisQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(FinReceiptHisQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private FinReceiptHisQuery query;		
	}



	[Serializable]
	abstract public partial class esFinReceiptHisCollection : esEntityCollection<FinReceiptHis>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return FinReceiptHisMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "FinReceiptHisCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public FinReceiptHisQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new FinReceiptHisQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(FinReceiptHisQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new FinReceiptHisQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(FinReceiptHisQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((FinReceiptHisQuery)query);
		}

		#endregion
		
		private FinReceiptHisQuery query;
	}



	[Serializable]
	abstract public partial class esFinReceiptHisQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return FinReceiptHisMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "HisId": return this.HisId;
				case "ReceiptId": return this.ReceiptId;
				case "Content": return this.Content;
				case "CreateUser": return this.CreateUser;
				case "CreateDate": return this.CreateDate;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem HisId
		{
			get { return new esQueryItem(this, FinReceiptHisMetadata.ColumnNames.HisId, esSystemType.Decimal); }
		} 
		
		public esQueryItem ReceiptId
		{
			get { return new esQueryItem(this, FinReceiptHisMetadata.ColumnNames.ReceiptId, esSystemType.Decimal); }
		} 
		
		public esQueryItem Content
		{
			get { return new esQueryItem(this, FinReceiptHisMetadata.ColumnNames.Content, esSystemType.String); }
		} 
		
		public esQueryItem CreateUser
		{
			get { return new esQueryItem(this, FinReceiptHisMetadata.ColumnNames.CreateUser, esSystemType.String); }
		} 
		
		public esQueryItem CreateDate
		{
			get { return new esQueryItem(this, FinReceiptHisMetadata.ColumnNames.CreateDate, esSystemType.DateTime); }
		} 
		
		#endregion
		
	}


	
	public partial class FinReceiptHis : esFinReceiptHis
	{

		
		
	}
	



	[Serializable]
	public partial class FinReceiptHisMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected FinReceiptHisMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(FinReceiptHisMetadata.ColumnNames.HisId, 0, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = FinReceiptHisMetadata.PropertyNames.HisId;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 18;
			m_columns.Add(c);
				
			c = new esColumnMetadata(FinReceiptHisMetadata.ColumnNames.ReceiptId, 1, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = FinReceiptHisMetadata.PropertyNames.ReceiptId;
			c.NumericPrecision = 18;
			m_columns.Add(c);
				
			c = new esColumnMetadata(FinReceiptHisMetadata.ColumnNames.Content, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = FinReceiptHisMetadata.PropertyNames.Content;
			c.CharacterMaxLength = 1073741823;
			m_columns.Add(c);
				
			c = new esColumnMetadata(FinReceiptHisMetadata.ColumnNames.CreateUser, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = FinReceiptHisMetadata.PropertyNames.CreateUser;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(FinReceiptHisMetadata.ColumnNames.CreateDate, 4, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = FinReceiptHisMetadata.PropertyNames.CreateDate;
			c.IsNullable = true;
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public FinReceiptHisMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string HisId = "HisId";
			 public const string ReceiptId = "ReceiptId";
			 public const string Content = "Content";
			 public const string CreateUser = "CreateUser";
			 public const string CreateDate = "CreateDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string HisId = "HisId";
			 public const string ReceiptId = "ReceiptId";
			 public const string Content = "Content";
			 public const string CreateUser = "CreateUser";
			 public const string CreateDate = "CreateDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(FinReceiptHisMetadata))
			{
				if(FinReceiptHisMetadata.mapDelegates == null)
				{
					FinReceiptHisMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (FinReceiptHisMetadata.meta == null)
				{
					FinReceiptHisMetadata.meta = new FinReceiptHisMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("HisId", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("ReceiptId", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("Content", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreateUser", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreateDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				meta.Source = "Fin_Receipt_His";
				meta.Destination = "Fin_Receipt_His";
				
				meta.spInsert = "proc_Fin_Receipt_HisInsert";				
				meta.spUpdate = "proc_Fin_Receipt_HisUpdate";		
				meta.spDelete = "proc_Fin_Receipt_HisDelete";
				meta.spLoadAll = "proc_Fin_Receipt_HisLoadAll";
				meta.spLoadByPrimaryKey = "proc_Fin_Receipt_HisLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private FinReceiptHisMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
